﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FileHelpers;
using FileHelpers.DataLink;
using System.Net;
using System.IO;
using FtpLib;
using System.Data.SqlClient;
using System.Security.Cryptography;

namespace CDRtoSQL
{
    public partial class Form1 : Form
    {
        #region Наработки которые не актуальны
        //Код позволяет загружать файлы с фтп сервера и импортировать в базу. импортированные файлы переименовываются.
        /* 
        FtpConnection ftpEl = new FtpConnection("172.24.145.7", "el", "el");
        ftpEl.Open();
        ftpEl.Login();
        foreach (var filen in ftpEl.GetFiles("el-*"))
        {
            ftpEl.GetFile(filen.Name, filen.Name, false);
            ReadCDRFile(filen.Name);
            InsertFileToSQL();
            File.Delete(filen.Name);
            //ftpEl.RenameFile(filen.Name, "processed_"+filen.Name); //переименовывает загруженные файлы
        }*/

        /*public DateTime GetDateTimeFromDB(string sqlQueryText)
        {

            using (SqlConnection sqlConn = new SqlConnection("Server=ULH-VM-SQL4;Database=CDRStats;Trusted_Connection=True;"))
            {
                SqlCommand sqlQuery = new SqlCommand(sqlQueryText, sqlConn);
                sqlConn.Open();
                SqlDataReader reader = sqlQuery.ExecuteReader();
                reader.Read();
                DateTime returnDate = ConvertFromUnixTimestamp((double)reader.GetInt64(0));
                reader.Close();
                sqlConn.Close();
                return returnDate;
            }

        }*/

        /*public ArrayList GetWorkDataBetweenDatesFromSQL()
        {
            ArrayList dataToCount = new ArrayList();
            string selectRangeQuery = "SELECT * FROM [CDRStats].[dbo].[CDRStats] WHERE h323_connect_time>=\'" + ConvertToUnixTimestamp(dateTimePicker1.Value) + "\' AND h323_disconnect_time<=\'" + ConvertToUnixTimestamp(dateTimePicker2.Value) + "\'";
            using (SqlConnection sqlConn = new SqlConnection("Server=ULH-VM-SQL4;Database=CDRStats;Trusted_Connection=True;"))
            {
                SqlCommand sqlQuery = new SqlCommand(selectRangeQuery, sqlConn);
                sqlConn.Open();
                SqlDataReader reader = sqlQuery.ExecuteReader();

                while (reader.Read())
                {
                    DataFromSQL res = new DataFromSQL();
                    res.unix_time = reader.GetInt64(0);
                    res.call_id = reader.GetInt32(1);
                    res.h323_conf_id = reader.GetString(2);
                    res.clid = reader.GetInt64(3);
                    res.dnis = reader.GetInt64(4);
                    res.h323_connect_time = ConvertFromUnixTimestamp(reader.GetInt64(5));
                    res.h323_disconnect_time = ConvertFromUnixTimestamp(reader.GetInt64(6));
                    res.disconnect_text = reader.GetString(7);
                    dataToCount.Add(res);
                }
                return dataToCount;
            }
        }*/


        /*public class DataFromSQL
        {
            public Int64 unix_time;
            public int call_id;
            public string h323_conf_id;
            public Int64 clid;
            public Int64 dnis;
            public DateTime h323_connect_time;
            public DateTime h323_disconnect_time;
            public string disconnect_text;
        }*/


        #endregion
    }
}